@model ContactManager.Models.Contact
@using ContactManager.Authorization;

@{
    ViewData["Title"] = "Details";
}

<h2>Details</h2>

<div>
    <h4>Contact</h4>
    <hr />
    <dl class="dl-horizontal">
        <dt>
            @Html.DisplayNameFor(model => model.Name)
        </dt>
        <dd>
            @Html.DisplayFor(model => model.Name)
        </dd>
        <dt>
            @Html.DisplayNameFor(model => model.Email)
        </dt>
        <dd>
            @Html.DisplayFor(model => model.Email)
        </dd>
        <dt>
            @Html.DisplayNameFor(model => model.Address)
        </dt>
        <dd>
            @Html.DisplayFor(model => model.Address)
        </dd>
        <dt>
            @Html.DisplayNameFor(model => model.City)
        </dt>
        <dd>
            @Html.DisplayFor(model => model.City)
        </dd>
        <dt>
            @Html.DisplayNameFor(model => model.State)
        </dt>
        <dd>
            @Html.DisplayFor(model => model.State)
        </dd>
        <dt>
            @Html.DisplayNameFor(model => model.Zip)
        </dt>
        <dd>
            @Html.DisplayFor(model => model.Zip)
        </dd>
        <dt>
            @Html.DisplayNameFor(model => model.Status)
        </dt>
        <dd>
            @Html.DisplayFor(model => model.Status)
        </dd>
    </dl>
</div>
@if (Model.Status != ContactStatus.Approved)
{
    @if (await AuthorizationService.AuthorizeAsync(User, Model, ContactOperations.Approve))
    {
        <form asp-action="SetStatus" asp-controller="Contacts" style="display:inline;">
            <input type="hidden" name="id" value="@Model.ContactId" />
            <input type="hidden" name="status" value="@ContactStatus.Approved" />
            <button type="submit" class="btn btn-xs btn-success">Approve</button>
        </form>
    }  
}
@if (Model.Status != ContactStatus.Rejected)
{
    @if (await AuthorizationService.AuthorizeAsync(User, Model, ContactOperations.Reject))
    {
        <form asp-action="SetStatus" asp-controller="Contacts" style="display:inline;">
            <input type="hidden" name="id" value="@Model.ContactId" />
            <input type="hidden" name="status" value="@ContactStatus.Rejected" />
            <button type="submit" class="btn btn-xs btn-danger">Reject</button>
        </form>
    }
}
<div>
    <a asp-action="Edit" asp-route-id="@Model.ContactId">Edit</a> |
    <a asp-action="Index">Back to List</a>
</div>
